package com.zz.rpc;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理类
 */
public class RemoteInvocationHandler implements InvocationHandler {
    public RemoteInvocationHandler(String host, int port) {
        this.host = host;
        this.port = port;
    }

    private String host;
    private int port;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("begin:" + host + "------->" + port);
        RpcReequest reequest = new RpcReequest();
        reequest.setClassName(method.getDeclaringClass().getName());
        reequest.setMethodName(method.getName());
        reequest.setParams(args);


        /*****************************************************************************/
        /************************************************************/
        /*************************************************/
        /****************    真正的远程调用    ******/
        RpcNetTransport r=new RpcNetTransport(host,port);
        Object result=r.send(reequest);


        return result;
    }
}
